package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.TimeSettingMapper;
import com.lanyan.system.domain.TimeSetting;
import com.lanyan.system.domain.vo.TimeSettingVo;
import com.lanyan.system.service.ITimeSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 时间设置Service业务层处理
 *
 * @author lanyan
 * @date 2025-09-04
 */
@Service
public class TimeSettingServiceImpl  extends ServiceImpl<TimeSettingMapper,TimeSetting> implements ITimeSettingService

{
    @Autowired
    private TimeSettingMapper timeSettingMapper;

    /**
     * 查询时间设置
     *
     * @param timeSettingId 时间设置主键
     * @return 时间设置
     */
    @Override
    public TimeSetting selectTimeSettingByTimeSettingId(Long timeSettingId)
    {
        return this.getById(timeSettingId);
    }

    /**
     * 查询时间设置Vo列表
     *
     * @param timeSetting 时间设置
     * @return 时间设置
     */
    @Override
    public List<TimeSettingVo> selectTimeSettingVoList(TimeSetting timeSetting)
    {
        return selectTimeSettingList(timeSetting)
                .stream()
                .map(x -> (TimeSettingVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询时间设置列表
     *
     * @param timeSetting 时间设置
     * @return 时间设置
     */
    @Override
    public List<TimeSetting> selectTimeSettingList(TimeSetting timeSetting)
    {
        LambdaQueryChainWrapper<TimeSetting> wrapper = this.lambdaQuery().eq(TimeSetting::getDelFlag,"0");
        if (timeSetting.getTimeStart() != null) {
            wrapper.eq(TimeSetting::getTimeStart, timeSetting.getTimeStart());
        }
        if (timeSetting.getTimeEnd() != null) {
            wrapper.eq(TimeSetting::getTimeEnd, timeSetting.getTimeEnd());
        }
        return wrapper.list();
    }

        /**
         * 新增时间设置
         *
         * @param timeSetting 时间设置
         * @return 结果
         */
    @Override
        public boolean insertTimeSetting(TimeSetting timeSetting)
        {
                    timeSetting.setCreateTime(DateUtils.getNowDate());
                return this.save(timeSetting);
        }

        /**
         * 修改时间设置
         *
         * @param timeSetting 时间设置
         * @return 结果
         */
    @Override
        public boolean updateTimeSetting(TimeSetting timeSetting)
        {
                    timeSetting.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(timeSetting);
        }

        /**
         * 批量删除时间设置
         *
         * @param timeSettingIds 需要删除的时间设置主键
         * @return 结果
         */
    @Override
        public boolean deleteTimeSettingByTimeSettingIds(Long[] timeSettingIds)
        {
            return this.lambdaUpdate().set(TimeSetting::getDelFlag,"1").in(TimeSetting::getTimeSettingId,timeSettingIds).update();
        }

        /**
         * 删除时间设置信息
         *
         * @param timeSettingId 时间设置主键
         * @return 结果
         */
    @Override
        public boolean deleteTimeSettingByTimeSettingId(Long timeSettingId)
        {
            return this.lambdaUpdate().set(TimeSetting::getDelFlag,"1").eq(TimeSetting::getTimeSettingId,timeSettingId).update();
        }
    }
